import org.eclipse.jetty.jmx.MBeanContainer;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.websocket.jsr356.server.ServerContainer;
import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer;

import java.lang.management.ManagementFactory;

/**
 * Created by xuwei on 2014/11/10.
 */
public class HelloServer {

    public static void main(String[] args) throws Exception {
        Server server = new Server(8080);

        // Setup JMX
        MBeanContainer mbContainer=new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
        server.addBean(mbContainer);

        WebAppContext webapp = new WebAppContext();
        webapp.setContextPath("/");
        webapp.setWar("E:\\IdeaProjects\\study-websocket\\ws-jetty\\src\\main");

        server.setHandler(webapp);
        webapp.addServlet(HelloWorldServlet.class,"/helloworld");

        ServerContainer wsContainer = WebSocketServerContainerInitializer.configureContext(webapp);
        wsContainer.addEndpoint(WsServerJsr.EchoJsrSocket.class);

        server.start();
        server.join();
    }
}
